package com.cn.wx.tread;

import java.util.Timer;
import java.util.TimerTask;

public class TimerTest {
    public static void main(String[] args) {
        new TimerTest().aa();
    }

    //    启动一个定时器，所以定时器算是一个线程
    Timer timer = new Timer();

    public void aa() {
        final int[] a = {0};
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println(a[0]++);
                if (a[0] == 6) {
                    System.out.println("定时器取消");
                    timer.cancel();
                }
            }
        }, 4000, 2000);


    }


}
